<html>
<head><meta charset="utf-8"><title>Devitrualizing diagnostics · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html">Devitrualizing diagnostics</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="236208360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236208360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236208360">(Apr 26 2021 at 17:00)</a>:</h4>
<p>Hey, anyone got strong feelings about <a href="https://github.com/rust-analyzer/rust-analyzer/issues/8672">https://github.com/rust-analyzer/rust-analyzer/issues/8672</a> ?</p>



<a name="236208474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236208474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236208474">(Apr 26 2021 at 17:01)</a>:</h4>
<p>It's going to be a major refactor, I am 80% sure that it's the right call, but I want to double check</p>



<a name="236208608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236208608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236208608">(Apr 26 2021 at 17:02)</a>:</h4>
<p>no strong feelings one way or the other. if we do change it, what do we gain?</p>



<a name="236209361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236209361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236209361">(Apr 26 2021 at 17:07)</a>:</h4>
<p>I bunch of simplicity in one of the more complicated  parth of the code base.</p>



<a name="236209446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236209446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236209446">(Apr 26 2021 at 17:08)</a>:</h4>
<p>Like, I dread working on the diagnostics code, because the level of indirecion is just way over my head :)</p>



<a name="236209643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236209643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236209643">(Apr 26 2021 at 17:09)</a>:</h4>
<p>oh, okay, then it's probably worth it</p>



<a name="236209828"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236209828" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236209828">(Apr 26 2021 at 17:10)</a>:</h4>
<p>I think about the case of removing generics from protocol conversion code</p>
<p><a href="https://github.com/rust-analyzer/rust-analyzer/pull/4418/commits/1586bab0b97bef411e6187dfc389557edbc5a16e">https://github.com/rust-analyzer/rust-analyzer/pull/4418/commits/1586bab0b97bef411e6187dfc389557edbc5a16e</a></p>



<a name="236209865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236209865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236209865">(Apr 26 2021 at 17:10)</a>:</h4>
<p>That definitely was very helpful</p>



<a name="236212750"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236212750" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236212750">(Apr 26 2021 at 17:29)</a>:</h4>
<p>won't this lead to a bunch of enums like <code>hir_expand::Diagnostic</code> and <code>hir_ty::Diagnostic</code> that are subsets of the big <code>hir::Diagnostic</code> enum? actually, how would this even look with accumulator style, since e.g. <code>hir_ty</code> can't produce <code>hir::Diagnostic</code>s?</p>



<a name="236212951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236212951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236212951">(Apr 26 2021 at 17:30)</a>:</h4>
<p>I _guess_ hir_ty's methods could take a type parameter <code>D: From&lt;hir_ty::Diagnostic&gt;</code></p>



<a name="236212993"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236212993" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236212993">(Apr 26 2021 at 17:30)</a>:</h4>
<p>not sure that still looks less complicated than the current setup though</p>



<a name="236215527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236215527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236215527">(Apr 26 2021 at 17:47)</a>:</h4>
<p><span class="user-mention" data-user-id="129457">@Florian Diebold</span> I am imagining the setup like in the rest of hir. There's a bunch of diagnostics with raw ids in various crates. Then, there's this giant enum in hir, which mirrors those raw diagnostics, but encapsulates the types, and the code to map between the two (so, a whole tone of boilerplate, a-la <code>hir/src/lib.rs</code>),</p>



<a name="236215603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236215603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236215603">(Apr 26 2021 at 17:47)</a>:</h4>
<p>This is already happening in some sense:</p>
<p><a href="/user_uploads/4715/rDn_cRFUmgGinZA2_wubdQF2/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/rDn_cRFUmgGinZA2_wubdQF2/image.png" title="image.png"><img src="/user_uploads/4715/rDn_cRFUmgGinZA2_wubdQF2/image.png"></a></div>



<a name="236215623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236215623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236215623">(Apr 26 2021 at 17:47)</a>:</h4>
<p>the impl block sort-of duplicates the <code>struct</code></p>



<a name="236215717"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236215717" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236215717">(Apr 26 2021 at 17:48)</a>:</h4>
<p>For accumulator style, we'll be just pushing onto a Vec</p>



<a name="236216187"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236216187" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236216187">(Apr 26 2021 at 17:51)</a>:</h4>
<p>We actually already do collect to vec in the most importatn case -- fn bodies: <a href="https://github.com/matklad/rust-analyzer/blob/f06e4b8e74bc2cec1fec4075f64b9909356c2bd3/crates/hir_def/src/body.rs#L419-L424">https://github.com/matklad/rust-analyzer/blob/f06e4b8e74bc2cec1fec4075f64b9909356c2bd3/crates/hir_def/src/body.rs#L419-L424</a></p>



<a name="236217117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236217117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236217117">(Apr 26 2021 at 17:58)</a>:</h4>
<p>I guess, there's also this issue:</p>
<p>It seems that diagnostics should speak the language of <code>hir</code>. That's our public API, and seems the right level of abstraction for <em>consumption</em> of diagnostics.  But the <code>trait Diagnostic</code> is defined in <code>hir_expand</code>, so it can't use hir-types</p>



<a name="236217193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236217193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236217193">(Apr 26 2021 at 17:58)</a>:</h4>
<p>(there's an obvious problem here is that we don't really have <code>hir</code> for expressions, but that's where most of the diagnostics are coming from)</p>



<a name="236323460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing%20diagnostics/near/236323460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jeremy Kolb <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Devitrualizing.20diagnostics.html#236323460">(Apr 27 2021 at 12:01)</a>:</h4>
<p>I think this would be a good cleanup. The diagnostics code is really kind of scary.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>